const router = require('express').Router();
const prisma = require('../db/client');
const middleware = require('@blocklet/sdk/lib/middlewares');
const {logger} = require('@blocklet/sdk/lib/config');
const user = middleware.user();


router.get('/list', user, async (req, res) => {

  const query = req.query
  await prisma.$connect();
  const list = await prisma.line.findMany({
    skip: query.pageNum * query.pageSize,
    take: query.pageSize * 1,
    orderBy: {
      line_time: 'desc',
    },
  })
  res.json(list)
})

router.post('/create', user, async (req, res) => {
  const body = req.body;
  await prisma.$connect();
  const line = await prisma.line.create({data: body})
  await prisma.$disconnect()
  res.json(line);
});


module.exports = router;
